// 实验1 RTOS任务调度

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

// 1. 创建任务句柄
static TaskHandle_t taskA_handle;
static TaskHandle_t taskB_handle;

// 2. 发送通知
void taskA(void *param)
{
    uint32_t value = 0;
    while (1)
    {
        // 定时发送(一定要注意，先保证taskB运行起来了，才能成功发送通知!!!)
        xTaskNotify(taskB_handle, value, eSetValueWithOverwrite);
        // ESP_LOGI("main","hello world!");
        vTaskDelay(pdMS_TO_TICKS(500));
        value++;
        value++;
    }
}

// 3. 接收通知
void taskB(void *param)
{
    uint32_t temp;
    while (1)
    {
        xTaskNotifyWait(0x00, ULONG_MAX, &temp, portMAX_DELAY);
        ESP_LOGI("notify", "recive data: %lu", temp);
    }
}

void app_main(void)
{
    xTaskCreatePinnedToCore(taskB, "taskB", 2048, NULL, 3, &taskB_handle, 1);
    xTaskCreatePinnedToCore(taskA, "taskA", 2048, NULL, 3, &taskA_handle, 1);
}
